package com.ssy.lingxi.product.controller.mobile;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.product.api.model.response.CommodityPriceRecordResponse;
import com.ssy.lingxi.product.api.model.response.OftenBuyCommodityResponse;
import com.ssy.lingxi.product.service.ICommodityService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @menu: APP-商品管理
 * 货品管理
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/30
 */
@RestController
@RequestMapping("/product/mobile/commodity")
public class MobileCommodityController extends BaseController {

    @Resource
    private ICommodityService commodityService;

    @Resource
    private HttpServletRequest request;

    /**
     * 查询商品历史价格
     * @param commoditySkuId  商品Skuid
     * @param days         最近多少天
     * @return 商品历史价格
     */
    @RequestMapping(value = "/getPriceRecord", method = RequestMethod.GET)
    public Wrapper<CommodityPriceRecordResponse> getPriceRecord(@RequestParam("commoditySkuId") Long commoditySkuId, @RequestParam("days") Integer days) {
        return Wrapper.success(commodityService.getPriceRecord(commoditySkuId, days));
    }

    /**
     * 查询常购清单列表
     * @param pageVO 分页实体
     * @param name 商品名称
     * @return 常购清单列表
     */
    @RequestMapping(value = "/getOftenBuyCommodityList", method = RequestMethod.GET)
    public Wrapper<PageData<OftenBuyCommodityResponse>> getOftenBuyCommodityList(PageVO pageVO, @RequestParam(value = "name", required = false) String name) {
        Long shopId = Long.parseLong(request.getHeader("shopId"));
        UserLoginCacheDTO sysUser = this.getSysUser(request);
        return Wrapper.success(commodityService.getOftenBuyCommodityList(pageVO, shopId, name, sysUser));
    }
}
